import 'package:flutter/material.dart';
import 'package:im_flutter_sdk_example/components/labels/index.dart';
import 'package:im_flutter_sdk_example/pages/expert/widgets/main_title.dart';
import 'package:im_flutter_sdk_example/components/comment/comment.dart';
import 'package:im_flutter_sdk_example/provider/comment_model.dart';
import 'package:provider/provider.dart';

class Comment extends StatefulWidget {
  final id;
  final type;
  final Function getFocus;
  Comment({Key key, this.id, this.type, this.getFocus}) : super(key: key);

  @override
  _CommentState createState() => _CommentState();
}

class _CommentState extends State<Comment> {
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      CommentModelProvider commentProvider =
          Provider.of<CommentModelProvider>(context);
      commentProvider.loadUserComments(widget.id.toString(), widget.type);
    });
  }

  @override
  Widget build(BuildContext context) {
    CommentModelProvider commentProvider =
        Provider.of<CommentModelProvider>(context);
    return Column(
      children: [
        MainTitle(title: '评论'),
        Container(
            color: Colors.white,
            child: Padding(
              padding: const EdgeInsets.all(0),
              child: Column(
                children: [
                  Column(
                    children: commentProvider.list
                        .map(
                          (item) => CommmentItem(
                              item: item, getFocus: widget.getFocus),
                        )
                        .toList(),
                  ),
                  LabelLoadAllComment()
                ],
              ),
            )),
      ],
    );
  }
}
